var t = require("../../../@babel/runtime/helpers/objectSpread2");

Component({
    properties: {
        datas: {
            type: null
        },
        component_id: {
            type: null
        }
    },
    data: {
        emptyImage: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/image.png",
        clientWidth: "375",
        countTime: 0,
        timeData: {},
        activity: {},
        activity_id: "",
        goods_id: "",
        options_id: "",
        activity_start: "",
        activity_end: "",
        currentTime: parseInt(new Date().getTime() / 1e3),
        activity_order: [],
        ladderList: [],
        steps: 0
    },
    lifetimes: {
        attached: function() {
            this.getActivity();
        },
        moved: function() {},
        detached: function() {}
    },
    attached: function() {},
    ready: function() {
        this.setData({
            clientWidth: wx.getSystemInfoSync().windowWidth
        });
    },
    methods: {
        toActivity: function() {
            wx.redirectTo({
                url: "/packageH/deposit_group/activity_index/activity_index?id=" + this.data.datas.activity.id
            });
        },
        onChange: function(t) {
            this.setData({
                timeData: t.detail
            });
        },
        getActivity: function() {
            var t;
            this.data.datas.activity && this.data.datas.activity.id && (t = this.data.datas.activity.activity_start > parseInt(Date.now() / 1e3) && 0 == this.data.datas.activity.status ? 1e3 * parseInt(this.data.datas.activity.activity_start - parseInt(Date.now() / 1e3)) : this.data.datas.activity.activity_end < Number(Date.now() / 1e3) || this.data.datas.activity.status > 0 ? 0 : 1e3 * parseInt(this.data.datas.activity.activity_end - parseInt(Date.now() / 1e3)), 
            this.setData({
                countTime: t,
                activity_id: this.data.datas.activity.id,
                goods_id: this.data.datas.activity.goods_id,
                goods_option_id: this.data.datas.activity.goods_option_id,
                activity_start: 1e3 * this.data.datas.activity.activity_start - new Date(),
                activity_end: 1e3 * this.data.datas.activity.activity_end - new Date(),
                activity: this.data.datas.activity
            }), this.resetSteps(this.data.datas.activity.ladder));
        },
        resetSteps: function(a) {
            var i = 0;
            a = a.reverse();
            var e = t({}, a[0]), d = this.data.activity;
            e.deal_price = d.bind_goods.price, a.unshift(e);
            for (var s = 0; s < a.length; s++) {
                if (0 === s && (1 === d.ladder_type && d.sale_count < a[s].sale_num || 0 === d.ladder_type && d.order_count < a[s].deal_num)) {
                    i = 0;
                    break;
                }
                (s > 0 && 1 === d.ladder_type && d.sale_count >= a[s].sale_num || 0 === d.ladder_type && d.order_count >= a[s].deal_num) && (i = s);
            }
            this.setData({
                steps: i,
                ladderList: a
            });
        }
    }
});